using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;
using System.Web;
using System.Threading;

namespace Data
{
	/// <summary>
	/// Strongly-typed collection for the article class.
	/// </summary>
	[Serializable]
	public partial class articleCollection : ActiveList<article, articleCollection> 
	{	   
		public articleCollection() {}

	}

	/// <summary>
	/// This is an ActiveRecord class which wraps the article table.
	/// </summary>
	[Serializable]
	public partial class article : ActiveRecord<article>
	{
		#region .ctors and Default Settings
		
		public article()
		{
		  SetSQLProps();
		  InitSetDefaults();
		  MarkNew();
		}

		
		private void InitSetDefaults() { SetDefaults(); }

		
		public article(bool useDatabaseDefaults)
		{
			SetSQLProps();
			if(useDatabaseDefaults)
				ForceDefaults();
			MarkNew();
		}

		public article(object keyID)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByKey(keyID);
		}

		 
		public article(string columnName, object columnValue)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByParam(columnName,columnValue);
		}

		
		protected static void SetSQLProps() { GetTableSchema(); }

		
		#endregion
		
		#region Schema and Query Accessor
		public static Query CreateQuery() { return new Query(Schema); }

		
		public static TableSchema.Table Schema
		{
			get
			{
				if (BaseSchema == null)
					SetSQLProps();
				return BaseSchema;
			}

		}

		
		private static void GetTableSchema() 
		{
			if(!IsSchemaInitialized)
			{
				//Schema declaration
				TableSchema.Table schema = new TableSchema.Table("article", TableType.Table, DataService.GetInstance("MyProvider"));
				schema.Columns = new TableSchema.TableColumnCollection();
				schema.SchemaName = @"";
				//columns
				
				TableSchema.TableColumn colvarArtID = new TableSchema.TableColumn(schema);
				colvarArtID.ColumnName = "ArtID";
				colvarArtID.DataType = DbType.String;
				colvarArtID.MaxLength = 40;
				colvarArtID.AutoIncrement = false;
				colvarArtID.IsNullable = false;
				colvarArtID.IsPrimaryKey = true;
				colvarArtID.IsForeignKey = false;
				colvarArtID.IsReadOnly = false;
				colvarArtID.DefaultSetting = @"";
				colvarArtID.ForeignKeyTableName = "";
				schema.Columns.Add(colvarArtID);
				
				TableSchema.TableColumn colvarArtCateID = new TableSchema.TableColumn(schema);
				colvarArtCateID.ColumnName = "ArtCateID";
				colvarArtCateID.DataType = DbType.String;
				colvarArtCateID.MaxLength = 40;
				colvarArtCateID.AutoIncrement = false;
				colvarArtCateID.IsNullable = true;
				colvarArtCateID.IsPrimaryKey = false;
				colvarArtCateID.IsForeignKey = false;
				colvarArtCateID.IsReadOnly = false;
				colvarArtCateID.DefaultSetting = @"";
				colvarArtCateID.ForeignKeyTableName = "";
				schema.Columns.Add(colvarArtCateID);
				
				TableSchema.TableColumn colvarTitle = new TableSchema.TableColumn(schema);
				colvarTitle.ColumnName = "Title";
				colvarTitle.DataType = DbType.String;
				colvarTitle.MaxLength = 500;
				colvarTitle.AutoIncrement = false;
				colvarTitle.IsNullable = true;
				colvarTitle.IsPrimaryKey = false;
				colvarTitle.IsForeignKey = false;
				colvarTitle.IsReadOnly = false;
				colvarTitle.DefaultSetting = @"";
				colvarTitle.ForeignKeyTableName = "";
				schema.Columns.Add(colvarTitle);
				
				TableSchema.TableColumn colvarShortDescript = new TableSchema.TableColumn(schema);
				colvarShortDescript.ColumnName = "ShortDescript";
				colvarShortDescript.DataType = DbType.String;
				colvarShortDescript.MaxLength = 1000;
				colvarShortDescript.AutoIncrement = false;
				colvarShortDescript.IsNullable = true;
				colvarShortDescript.IsPrimaryKey = false;
				colvarShortDescript.IsForeignKey = false;
				colvarShortDescript.IsReadOnly = false;
				colvarShortDescript.DefaultSetting = @"";
				colvarShortDescript.ForeignKeyTableName = "";
				schema.Columns.Add(colvarShortDescript);
				
				TableSchema.TableColumn colvarContent = new TableSchema.TableColumn(schema);
				colvarContent.ColumnName = "Content";
				colvarContent.DataType = DbType.String;
				colvarContent.MaxLength = 0;
				colvarContent.AutoIncrement = false;
				colvarContent.IsNullable = true;
				colvarContent.IsPrimaryKey = false;
				colvarContent.IsForeignKey = false;
				colvarContent.IsReadOnly = false;
				colvarContent.DefaultSetting = @"";
				colvarContent.ForeignKeyTableName = "";
				schema.Columns.Add(colvarContent);
				
				TableSchema.TableColumn colvarActive = new TableSchema.TableColumn(schema);
				colvarActive.ColumnName = "Active";
				colvarActive.DataType = DbType.Boolean;
				colvarActive.MaxLength = 1;
				colvarActive.AutoIncrement = false;
				colvarActive.IsNullable = true;
				colvarActive.IsPrimaryKey = false;
				colvarActive.IsForeignKey = false;
				colvarActive.IsReadOnly = false;
				colvarActive.DefaultSetting = @"";
				colvarActive.ForeignKeyTableName = "";
				schema.Columns.Add(colvarActive);
				
				TableSchema.TableColumn colvarStatus = new TableSchema.TableColumn(schema);
				colvarStatus.ColumnName = "Status";
				colvarStatus.DataType = DbType.Int32;
				colvarStatus.MaxLength = 11;
				colvarStatus.AutoIncrement = false;
				colvarStatus.IsNullable = true;
				colvarStatus.IsPrimaryKey = false;
				colvarStatus.IsForeignKey = false;
				colvarStatus.IsReadOnly = false;
				colvarStatus.DefaultSetting = @"";
				colvarStatus.ForeignKeyTableName = "";
				schema.Columns.Add(colvarStatus);
				
				TableSchema.TableColumn colvarVipLevel = new TableSchema.TableColumn(schema);
				colvarVipLevel.ColumnName = "VipLevel";
				colvarVipLevel.DataType = DbType.Int32;
				colvarVipLevel.MaxLength = 11;
				colvarVipLevel.AutoIncrement = false;
				colvarVipLevel.IsNullable = true;
				colvarVipLevel.IsPrimaryKey = false;
				colvarVipLevel.IsForeignKey = false;
				colvarVipLevel.IsReadOnly = false;
				colvarVipLevel.DefaultSetting = @"";
				colvarVipLevel.ForeignKeyTableName = "";
				schema.Columns.Add(colvarVipLevel);
				
				TableSchema.TableColumn colvarViewed = new TableSchema.TableColumn(schema);
				colvarViewed.ColumnName = "Viewed";
				colvarViewed.DataType = DbType.Double;
				colvarViewed.MaxLength = 0;
				colvarViewed.AutoIncrement = false;
				colvarViewed.IsNullable = true;
				colvarViewed.IsPrimaryKey = false;
				colvarViewed.IsForeignKey = false;
				colvarViewed.IsReadOnly = false;
				colvarViewed.DefaultSetting = @"";
				colvarViewed.ForeignKeyTableName = "";
				schema.Columns.Add(colvarViewed);
				
				TableSchema.TableColumn colvarImage = new TableSchema.TableColumn(schema);
				colvarImage.ColumnName = "Image";
				colvarImage.DataType = DbType.String;
				colvarImage.MaxLength = 1000;
				colvarImage.AutoIncrement = false;
				colvarImage.IsNullable = true;
				colvarImage.IsPrimaryKey = false;
				colvarImage.IsForeignKey = false;
				colvarImage.IsReadOnly = false;
				colvarImage.DefaultSetting = @"";
				colvarImage.ForeignKeyTableName = "";
				schema.Columns.Add(colvarImage);
				
				TableSchema.TableColumn colvarAuthor = new TableSchema.TableColumn(schema);
				colvarAuthor.ColumnName = "Author";
				colvarAuthor.DataType = DbType.String;
				colvarAuthor.MaxLength = 255;
				colvarAuthor.AutoIncrement = false;
				colvarAuthor.IsNullable = true;
				colvarAuthor.IsPrimaryKey = false;
				colvarAuthor.IsForeignKey = false;
				colvarAuthor.IsReadOnly = false;
				colvarAuthor.DefaultSetting = @"";
				colvarAuthor.ForeignKeyTableName = "";
				schema.Columns.Add(colvarAuthor);
				
				TableSchema.TableColumn colvarHot = new TableSchema.TableColumn(schema);
				colvarHot.ColumnName = "Hot";
				colvarHot.DataType = DbType.Boolean;
				colvarHot.MaxLength = 1;
				colvarHot.AutoIncrement = false;
				colvarHot.IsNullable = true;
				colvarHot.IsPrimaryKey = false;
				colvarHot.IsForeignKey = false;
				colvarHot.IsReadOnly = false;
				colvarHot.DefaultSetting = @"";
				colvarHot.ForeignKeyTableName = "";
				schema.Columns.Add(colvarHot);
				
				TableSchema.TableColumn colvarCreatedDate = new TableSchema.TableColumn(schema);
				colvarCreatedDate.ColumnName = "CreatedDate";
				colvarCreatedDate.DataType = DbType.DateTime;
				colvarCreatedDate.MaxLength = 0;
				colvarCreatedDate.AutoIncrement = false;
				colvarCreatedDate.IsNullable = true;
				colvarCreatedDate.IsPrimaryKey = false;
				colvarCreatedDate.IsForeignKey = false;
				colvarCreatedDate.IsReadOnly = false;
				colvarCreatedDate.DefaultSetting = @"";
				colvarCreatedDate.ForeignKeyTableName = "";
				schema.Columns.Add(colvarCreatedDate);
				
				TableSchema.TableColumn colvarUpdatedDate = new TableSchema.TableColumn(schema);
				colvarUpdatedDate.ColumnName = "UpdatedDate";
				colvarUpdatedDate.DataType = DbType.DateTime;
				colvarUpdatedDate.MaxLength = 0;
				colvarUpdatedDate.AutoIncrement = false;
				colvarUpdatedDate.IsNullable = true;
				colvarUpdatedDate.IsPrimaryKey = false;
				colvarUpdatedDate.IsForeignKey = false;
				colvarUpdatedDate.IsReadOnly = false;
				colvarUpdatedDate.DefaultSetting = @"";
				colvarUpdatedDate.ForeignKeyTableName = "";
				schema.Columns.Add(colvarUpdatedDate);
				
				BaseSchema = schema;
				//add this schema to the provider
				//so we can query it later
				DataService.Providers["MyProvider"].AddSchema("article",schema);
			}

		}

		#endregion
		
		#region Props
		
		  
		[XmlAttribute("ArtID")]
		public string ArtID 
		{
			get { return GetColumnValue<string>("ArtID"); }

			set { SetColumnValue("ArtID", value); }

		}

		  
		[XmlAttribute("ArtCateID")]
		public string ArtCateID 
		{
			get { return GetColumnValue<string>("ArtCateID"); }

			set { SetColumnValue("ArtCateID", value); }

		}

		  
		[XmlAttribute("Title")]
		public string Title 
		{
			get { return GetColumnValue<string>("Title"); }

			set { SetColumnValue("Title", value); }

		}

		  
		[XmlAttribute("ShortDescript")]
		public string ShortDescript 
		{
			get { return GetColumnValue<string>("ShortDescript"); }

			set { SetColumnValue("ShortDescript", value); }

		}

		  
		[XmlAttribute("Content")]
		public string Content 
		{
			get { return GetColumnValue<string>("Content"); }

			set { SetColumnValue("Content", value); }

		}

		  
		[XmlAttribute("Active")]
		public bool? Active 
		{
			get { return GetColumnValue<bool?>("Active"); }

			set { SetColumnValue("Active", value); }

		}

		  
		[XmlAttribute("Status")]
		public int? Status 
		{
			get { return GetColumnValue<int?>("Status"); }

			set { SetColumnValue("Status", value); }

		}

		  
		[XmlAttribute("VipLevel")]
		public int? VipLevel 
		{
			get { return GetColumnValue<int?>("VipLevel"); }

			set { SetColumnValue("VipLevel", value); }

		}

		  
		[XmlAttribute("Viewed")]
		public double? Viewed 
		{
			get { return GetColumnValue<double?>("Viewed"); }

			set { SetColumnValue("Viewed", value); }

		}

		  
		[XmlAttribute("Image")]
		public string Image 
		{
			get { return GetColumnValue<string>("Image"); }

			set { SetColumnValue("Image", value); }

		}

		  
		[XmlAttribute("Author")]
		public string Author 
		{
			get { return GetColumnValue<string>("Author"); }

			set { SetColumnValue("Author", value); }

		}

		  
		[XmlAttribute("Hot")]
		public bool? Hot 
		{
			get { return GetColumnValue<bool?>("Hot"); }

			set { SetColumnValue("Hot", value); }

		}

		  
		[XmlAttribute("CreatedDate")]
		public DateTime? CreatedDate 
		{
			get { return GetColumnValue<DateTime?>("CreatedDate"); }

			set { SetColumnValue("CreatedDate", value); }

		}

		  
		[XmlAttribute("UpdatedDate")]
		public DateTime? UpdatedDate 
		{
			get { return GetColumnValue<DateTime?>("UpdatedDate"); }

			set { SetColumnValue("UpdatedDate", value); }

		}

		
		#endregion
		
		
			
		
		//no foreign key tables defined (0)
		
		
		
		//no ManyToMany tables defined (0)
		
		#region ObjectDataSource support
		
		
		/// <summary>
		/// Inserts a record, can be used with the Object Data Source
		/// </summary>
		public static void Insert(string varArtID,string varArtCateID,string varTitle,string varShortDescript,string varContent,bool? varActive,int? varStatus,int? varVipLevel,double? varViewed,string varImage,string varAuthor,bool? varHot,DateTime? varCreatedDate,DateTime? varUpdatedDate)
		{
			article item = new article();
			
			item.ArtID = varArtID;
			
			item.ArtCateID = varArtCateID;
			
			item.Title = varTitle;
			
			item.ShortDescript = varShortDescript;
			
			item.Content = varContent;
			
			item.Active = varActive;
			
			item.Status = varStatus;
			
			item.VipLevel = varVipLevel;
			
			item.Viewed = varViewed;
			
			item.Image = varImage;
			
			item.Author = varAuthor;
			
			item.Hot = varHot;
			
			item.CreatedDate = varCreatedDate;
			
			item.UpdatedDate = varUpdatedDate;
			
		
			if (HttpContext.Current != null)
				item.Save(HttpContext.Current.User.Identity.Name);
			else
				item.Save(Thread.CurrentPrincipal.Identity.Name);
		}

		
		/// <summary>
		/// Updates a record, can be used with the Object Data Source
		/// </summary>
		public static void Update(string varArtID,string varArtCateID,string varTitle,string varShortDescript,string varContent,bool? varActive,int? varStatus,int? varVipLevel,double? varViewed,string varImage,string varAuthor,bool? varHot,DateTime? varCreatedDate,DateTime? varUpdatedDate)
		{
			article item = new article();
			
				item.ArtID = varArtID;
				
				item.ArtCateID = varArtCateID;
				
				item.Title = varTitle;
				
				item.ShortDescript = varShortDescript;
				
				item.Content = varContent;
				
				item.Active = varActive;
				
				item.Status = varStatus;
				
				item.VipLevel = varVipLevel;
				
				item.Viewed = varViewed;
				
				item.Image = varImage;
				
				item.Author = varAuthor;
				
				item.Hot = varHot;
				
				item.CreatedDate = varCreatedDate;
				
				item.UpdatedDate = varUpdatedDate;
				
			item.IsNew = false;
			if (HttpContext.Current != null)
				item.Save(HttpContext.Current.User.Identity.Name);
			else
				item.Save(Thread.CurrentPrincipal.Identity.Name);
		}

		#endregion
		#region Columns Struct
		public struct Columns
		{
			int i;
			 public static string ArtID = @"ArtID";
			 public static string ArtCateID = @"ArtCateID";
			 public static string Title = @"Title";
			 public static string ShortDescript = @"ShortDescript";
			 public static string Content = @"Content";
			 public static string Active = @"Active";
			 public static string Status = @"Status";
			 public static string VipLevel = @"VipLevel";
			 public static string Viewed = @"Viewed";
			 public static string Image = @"Image";
			 public static string Author = @"Author";
			 public static string Hot = @"Hot";
			 public static string CreatedDate = @"CreatedDate";
			 public static string UpdatedDate = @"UpdatedDate";
						
		}

		#endregion
	}

}

